/*
 * MeasureUnitClient.java
 *
 * $Id: MeasureUnitClient.java,v 1.9 2009-09-17 12:11:01 mario Exp $
 */
package org.ceteca.explica.client.warehouse;

import java.util.ArrayList;

import org.ceteca.explica.client.gui.common.CommonClient;
import org.ceteca.explica.core.common.BaseVO;
import org.ceteca.explica.core.util.OperationResult;
import org.ceteca.explica.core.warehouse.InterfaceWarehouse;
import org.ceteca.explica.core.warehouse.MeasureUnitOT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;

public class MeasureUnitClient extends CommonClient {
	/**
     * Message for logging the entity glade configuration file path.
     */
    public static final String EXPLICA_LOG_EDITMEASUREUNIT_GLADEPATH = "The measure unit edition interface configuration file has been found at this path: %s";
    
    public MeasureUnitClient() {
    	super(	MeasureUnitOT.class,
				InterfaceWarehouse.EXPLICA_EDIT_MEASUREUNIT_GLADE_PATH,
				InterfaceWarehouse.EDIT_MEASUREUNIT_DIALOG_NAME);
    }
	
    @Override
	public ArrayList getEntityFields() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void fillEntityData() {
		this.logger.info("Filling the entity with the selected registry data: " + this.entityEditGuiName);
		if (this.getSelectedEntity() != null && this.entEditView != null) {
			MeasureUnitOT mesUnit = (MeasureUnitOT)this.getSelectedEntity();
			// Set up the measure unit's id
			((Text)this.getWidget(InterfaceWarehouse.EDIT_MEASUREUNIT_CODE_WIDGETNAME)).setText(String.format("%d", mesUnit.getIdMeasureUnit()));
			// Set up the measure unit's description
			((StyledText)this.getWidget(InterfaceWarehouse.EDIT_MEASUREUNIT_DESCRIPTION_WIDGETNAME)).setText(mesUnit.getDescription());
		}
	}

	@Override
	public void clearEntityData() {
		if (this.entEditView != null) {
			// Clear the product group type's id
			((Text)this.getWidget(InterfaceWarehouse.EDIT_MEASUREUNIT_CODE_WIDGETNAME)).setText("");
			// Clear the product group type's description
			((StyledText)this.getWidget(InterfaceWarehouse.EDIT_MEASUREUNIT_DESCRIPTION_WIDGETNAME)).setText("");
		}
	}

	@Override
	public BaseVO getEntityData() {
		MeasureUnitOT measureUnit = new MeasureUnitOT();
		
		if (this.entEditView != null) {
			// Set up the product's description
			measureUnit.setDescription(((StyledText)this.getWidget(InterfaceWarehouse.EDIT_MEASUREUNIT_DESCRIPTION_WIDGETNAME)).getText());
		}
		
		if (this.getSelectedEntity() != null) {
			MeasureUnitOT mesUnit = (MeasureUnitOT)this.getSelectedEntity();
			measureUnit.setVersion(mesUnit.getVersion());
			measureUnit.setIdMeasureUnit(mesUnit.getIdMeasureUnit());
		}
		
		return measureUnit;
	}

	@Override
	public void updateEntityData() {
		if (this.getSelectedEntity() != null && this.entEditView != null) {
			// Set up the product's description
			((MeasureUnitOT)this.getSelectedEntity()).setDescription(((StyledText)this.getWidget(InterfaceWarehouse.EDIT_MEASUREUNIT_DESCRIPTION_WIDGETNAME)).getText());
		}
		
	}

	@Override
	public void setEditionMode(boolean enabled) {
		// Get the measure unit's code widget
		Control c = (Control)this.getWidget(InterfaceWarehouse.EDIT_MEASUREUNIT_CODE_WIDGETNAME);
		c.setEnabled(enabled);
		
		// Get the measure unit's description widget
		c = (Control)this.getWidget(InterfaceWarehouse.EDIT_MEASUREUNIT_DESCRIPTION_WIDGETNAME);
		c.setEnabled(enabled);
	}
	
	@Override
	public void build_extension_fields_view() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void buildSelectionSets() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void getWidgets() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void init_specific_components() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setWidgetsValues(BaseVO entity) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public OperationResult validateEntity() {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * Returns tag Id assigned to CVS source file.
	 */
	public static String getRevision() {
		return "$Id: MeasureUnitClient.java,v 1.9 2009-09-17 12:11:01 mario Exp $";
	}
}
